<!DOCTYPE html>
<html>
<title> 登陆 </title>
<head lang="en">
    <meta http-equiv="Content-Type" content="text/css; charset=utf-8">

    <link rel="stylesheet" href="{{ static_url('css/bootstrap.min.css') }}">
    <link rel="stylesheet" href="{{ static_url('css/pop.css') }}">

    <script src="{{ static_url('js/jquery.min.js')}}"></script>
    <script src="{{ static_url('js/pop.js') }}"></script>

    <style>
            .total {
                margin:         0 auto;
                text-align:     center;
                margin-top:     3cm;
                margin-bottom:  1cm;
                witdh:          18cm;
            }
        </style>
</head>

<body>

<div class="total">

    </br></br>

    <form class="form-inline" role="form">
        <div class="form-group">
            <label for="username" style="width: 60px"> 用户名： </label>
            <input type="username" class="form-control" style="width: 300px" id="username" placeholder="Enter username">
        </div>
    </form>

    <br>
    <form class="form-inline" role="form">
        <div class="form-group">
            <label for="password" style="width: 60px"> 密码： </label>
            <input type="password" class="form-control" style="width: 300px" id="password" placeholder="Enter password">
        </div>
    </form>

    <button type="button" class="btn btn-success" id="login" style="margin: 10px 10px 10px 10px"> 登陆 </button>
</div>

</body>

</html>


<script>

    var enterKeydown = function(e) {
        if (e.keyCode == 13) {
            e.preventDefault();
            login();
        }
    };

    function login() {
        var username = $('#username').val();
        var password = $('#password').val();
        console.log("username:" + username);
        console.log("password:" + password);
        if(!username) {
            showPopWindow("请输入用户名!");
            return;
        }
        if(!password) {
            showPopWindow("请输入密码!");
            return;
        }

        var host = window.location.host;
        $.post("http://"+host+"/login", {username: username, password: password},
            function(msg, status, xhr) {
                console.log("msg: " + JSON.stringify(msg));
                if (msg.code != 0) {
                    showPopWindow(msg.info);
                } else {
                    window.location.href = msg.redirect_url;
                }
            },
            "json"
        );
    }

    $(function() {

        /* 登陆 */
        $('#login').click(function() {
            login();
        });

        $("#username").keydown(function (e){
            enterKeydown();
        });

        $("#password").keydown(function (e){
            enterKeydown();
        });

    });

</script>
